use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use rpc::bootstrap::BootstrapBuilder;
use rpc_derive::{rpc_router};
use rpc_server::server::RpcServerBuilder;

// #[tokio::test]
pub async fn server_test() -> Result<(), Box<dyn std::error::Error>> {
    let bootstrap = BootstrapBuilder::new()
        .router("/login", Box::new(LoginRouterFactory))
        ;
    RpcServerBuilder::new(bootstrap, 8899)
        .build()
        .start_server().await?;
    Ok(())
}

#[rpc_router]
fn login() -> OkResp {

    OkResp {}
}

#[derive(Debug, Serialize, Deserialize, Encode, Decode, PartialEq)]
pub struct OkResp {

}

// impl RpcEncode for OkResp {
//     fn encode(&self, context: &RpcContext) -> RpcResult<Vec<u8>> {
//         encode(context, self)
//     }
// }

pub struct LoginReq {
    pub user_id: String,
}

// impl RpcDecode<LoginReq> for LoginReq {
//     fn decode(buf: &mut BytesMut) -> Result<LoginReq, RpcError>
//     where
//         Self: Sized
//     {
//         todo!()
//     }
// }
//
// impl RpcEncode for OkResp {
//     fn encode(&self, buf: &mut BytesMut) -> Result<(), RpcError> {
//         todo!()
//     }
// }